package com.ape.mapsa.produccion.dao;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.ape.mapsa.produccion.model.ConfPerformedWork;
import com.ape.mapsa.produccion.model.Confeccion;
import com.ape.mapsa.produccion.model.ExtPerformedWork;
import com.ape.mapsa.produccion.model.Extrusion;
import com.ape.mapsa.produccion.model.ImpPerformedWork;
import com.ape.mapsa.produccion.model.Impresion;

@Repository
public class PerformedWorkDAOImpl extends GenericDAOImpl<Object, Long> implements PerformedWorkDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<ExtPerformedWork> getExtrusionPerformedWork(Extrusion extrusion) {
		return sessionFactory.getCurrentSession().createCriteria(ExtPerformedWork.class).add(Restrictions.eq("extrusion", extrusion))
				.add(Restrictions.eq("state", 1)).list();
	}

	@Override
	public void saveExtPerformedWork(ExtPerformedWork extPerformedWork) {
		sessionFactory.getCurrentSession().save(ExtPerformedWork.class.getName(), extPerformedWork);
	}

	@Override
	public void updateExtPerformedWork(ExtPerformedWork extPerformedWork) {
		sessionFactory.getCurrentSession().update(ExtPerformedWork.class.getName(), extPerformedWork);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ConfPerformedWork> getConfPerformedWork(Confeccion confeccion) {
		return sessionFactory.getCurrentSession().createCriteria(ConfPerformedWork.class).add(Restrictions.eq("confeccion", confeccion))
				.add(Restrictions.eq("state", 1)).list();
	}

	@Override
	public void saveConfPerformedWork(ConfPerformedWork confPerforemdWork) {
		sessionFactory.getCurrentSession().save(ConfPerformedWork.class.getName(), confPerforemdWork);
	}

	@Override
	public void updateConfPerformedWork(ConfPerformedWork confPerforemdWork) {
		sessionFactory.getCurrentSession().update(ConfPerformedWork.class.getName(), confPerforemdWork);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ImpPerformedWork> getImpPerformedWork(Impresion impresion) {
		return sessionFactory.getCurrentSession().createCriteria(ImpPerformedWork.class).add(Restrictions.eq("impresion", impresion))
				.add(Restrictions.eq("state", 1)).list();
	}

	@Override
	public void saveImpPerformedWork(ImpPerformedWork impPerformedWork) {
		sessionFactory.getCurrentSession().save(ImpPerformedWork.class.getName(), impPerformedWork);
	}

	@Override
	public void updateImpPerformedWork(ImpPerformedWork impPerformedWork) {
		sessionFactory.getCurrentSession().update(ImpPerformedWork.class.getName(), impPerformedWork);
	}
}
